

import onload from '../util/onload';
import tracker from '../util/tracker';


export function timing() {
    onload(function () {
        
console.log(performance.timeOrigin);
        setTimeout(()=>{
            const {
                fetchStart, //请求开始
                connectStart, //开始连接
                connectEnd, //结束连接
                requestStart, //开始请求
                responseStart,//响应开始
                responseEnd,//响应结束
                domLoading,//开始解析dom
                domInteractive,//dom结构结束解析
                domContentLoadedEventStart,//domContentLoaded事件发生的时间
                domContentLoadedEventEnd,//domContentLoaded事件脚本执行完毕的时间,domReady的时间
                loadEventStart//oad回调函数开始执行的时间
            } = performance.timeOrigin
            tracker.send({
                kind: 'experience', //用户体验指标
                type: 'timing',
                connectTime: connectEnd - connectStart,//TCP连接耗时
                ttfbTime: responseStart - requestStart,//ttfb
                responseTime: responseEnd - responseStart,//Response响应耗时
                parseDOMTime: loadEventStart - domLoading,//DOM解析渲染耗时
                domContentLoadedTime: domContentLoadedEventEnd - domContentLoadedEventStart,//DOMContentLoaded事件回调耗时
                timeToInteractive: domInteractive - fetchStart,//首次可交互时间
                loadTime: loadEventStart - fetchStart//完整的加载时间
            });
        },3000)
    });
}